<%@page import="java.text.Normalizer.Form"%>
<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String username = user.getName();
	String userid = user.getUsername();
	String siteid = user.getSiteId();
	String sitename = user.getSiteName();
	TblCheckLeave leave = null;
	if (null != request.getAttribute("leave")){
		leave = (TblCheckLeave) request.getAttribute("leave");
	}
	String defaultSiteId = request.getAttribute("defaultSiteid")!=null?request.getAttribute("defaultSiteid")+"":"";
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
	String year_moth = sdf.format(new Date());
	String destroy  = request.getAttribute("destroy")!= null?request.getAttribute("destroy")+"":"";
%>

<div>
	<form target="_coreIframe" method="post" action="<%=request.getContextPath()%>/check/doEditLeave" enctype="multipart/form-data">
		<div class="breadcrumb">
			<div class="bcIcon"></div>
			<ul class="bcNav">
				<li id="toptitle">修改</li>
			</ul>
		</div>
		<input type="hidden" name="id" value="<%=leave.getId()+"" %>">
		<input type="hidden" name="siteid" value="<%=siteid%>">
		<table class="formTable">			
			<tr>
				<td class="tdTitle">所属公司：</td>
				<td>
					<input class="inputText xs" type="text" name="sitename" value="<%=sitename %>" readonly>
					<span class="errorTipWrap" id="errorTip_sitename"></span>
				</td>
			</tr>			
			<tr>
				<td class="tdTitle">员工姓名：</td>
				<td>
					<input class="inputText xs" type="text" name="username" value="<%=username %>" readonly>
					<span class="errorTipWrap" id="errorTip_username"></span>
				</td>
			</tr>	
			<tr>
				<td class="tdTitle">员工编号：</td>
				<td>
					<input class="inputText xs" type="text" name="userid" value="<%=userid %>" readonly>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">请假开始日期：</td>
				<td>
				<input class="inputText xs" type="text" value="<%=DateFormatUtils.format(leave.getStartdate(), "yyyy-MM-dd HH:mm:ss")%>"id="startDate" name="startDate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 08:00:00'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">请假结束日期：</td>
				<td>
				<input class="inputText xs" type="text" value="<%=DateFormatUtils.format(leave.getEnddate(), "yyyy-MM-dd HH:mm:ss")%>" id="endDate" name="endDate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 08:00:00'})">
				<span class="errorTipWrap" id="errorTip_endDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">请假类型：</td>
				<td>
					<select id="type" class="easyui-combobox" name="type" style="width:80px;"></select>
					<span class="errorTipWrap" id="errorTip_type"></span>
				</td>
			</tr>		
			<tr>
				<td class="tdTitle">请假原因：</td>
				<td><input class="inputText xs" type="text"  value="<%=null!=leave.getReason()?leave.getReason():"" %>" id="reason" name="reason"></td>
			</tr>
						
			<tr>
				<td class="tdTitle"></td>
				<td>
					<div>
						<input class="input-btn-microsoft" type="submit" value="提交">
						<a id="cancel" class="a-btn-microsoft" href="javascript:XF.Check.leaveList('<%=year_moth %>','<%=userid %>')">取消</a>
					</div>
				</td>
			</tr>	
		</table>
	</form>
	<iframe id="_coreIframe" name="_coreIframe" style="display: none;"></iframe>
</div>
<script>
var type = "<%=leave.getType()!=null?leave.getType():""%>";
$("#type").combobox({
		 valueField:'value',
		 textField:'id',
		 data:[{"id":"事假","value":"事假"},{"id":"病假","value":"病假"},{"id":"调休","value":"调休"},{"id":"出差","value":"出差"},
		       {"id":"年假","value":"年假"},{"id":"工伤假","value":"工伤假"},{"id":"婚假","value":"婚假"},
		       {"id":"产假","value":"产假"},{"id":"陪产假","value":"陪产假"},{"id":"丧假","value":"丧假"}],
		 panelHeight: 'auto',
		 value:type
	 });

$(document).ready(function() {
	var d = <%=destroy%>+"";
	if(d == '1'){
		$("#toptitle").html("员工申请请假销毁");
		$('#reason').attr('readonly','readonly');
		$('input[name=startDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('input[name=endDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('#type').combobox('readonly',true);		
		var userTr = "<tr><td class='tdTitle'><font color='#FF0000'>请假销毁原因：</font></td>";
		userTr += "<td><input class='inputText xs' type='text'  name='remark'><span><font color='#FF0000'>只填写销毁原因即可</font></span><span class='errorTipWrap' id='errorTip_remark'></span></td></tr>"
		userTr += "<input type='hidden' name='flag' value='3'>";
		$("tr:last").before(userTr);
		var url="<%=request.getContextPath()%>/check/doUserDestroyLeave"
		$("form").attr("action",url);
	}else if(d == 3){
		$("#toptitle").html("人事部不通过原因");
		$('#reason').attr('readonly','readonly');
		$('input[name=startDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('input[name=endDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('#type').combobox('readonly',true);
		$('#cancel').attr("href","javascript:XF.Check.leavePersonList('<%=year_moth %>','<%=defaultSiteId %>')")
		var userTr = "<tr><td class='tdTitle'><font color='#FF0000'>不通过原因：</font></td>";
		userTr += "<td><input class='inputText xs' type='text'  name='personremark'><span><font color='#FF0000'>只填写不通过原因即可</font></span><span class='errorTipWrap' id='errorTip_personremark'></span></td></tr>"
		userTr += "<input type='hidden' name='personflag' value='1'>";
		userTr += "<input type='hidden' name='personuser' value='<%=username%>'>";
		$("tr:last").before(userTr);
		var url="<%=request.getContextPath()%>/check/doNoPersonLeave"
		$("form").attr("action",url);
	}else if(d == 2){
		$("#toptitle").html("部门不通过请假原因");
		$('#reason').attr('readonly','readonly');
		$('input[name=startDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('input[name=endDate]').removeAttr('onclick').attr('readonly',"readonly");
		$('#type').combobox('readonly',true);
		$('#cancel').attr("href","javascript:XF.Check.leaveDeptList('<%=year_moth %>','<%=siteid %>','<%=user.getDeptId() %>')");
		var userTr = "<tr><td class='tdTitle'><font color='#FF0000'>不通过原因：</font></td>";
		userTr += "<td><input class='inputText xs' type='text'  name='deptremark'><span><font color='#FF0000'>只填写不通过原因即可</font></span><span class='errorTipWrap' id='errorTip_deptremark'></span></td></tr>"
		userTr += "<input type='hidden' name='deptflag' value='1'>";
		userTr += "<input type='hidden' name='deptuser' value='<%=username%>'>";
		$("tr:last").before(userTr);
		var url="<%=request.getContextPath()%>/check/doNoDeptLeave"
		$("form").attr("action",url);
	}else if(d = 4){		
		$('#cancel').attr("href","javascript:XF.Check.leavePersonList('<%=year_moth %>','<%=defaultSiteId %>')")
		var url="<%=request.getContextPath()%>/check/doEditPersonLeave"
		$("form").attr("action",url);
	}
});
</script>


